<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core">
    
    <h:head>
        <title>#{names.title}</title>
    </h:head>
    
    <h:body rendered="#{!auth.loggedIn}">
        <ui:include src="login.xhtml" />
    </h:body>
    
    <h:body rendered="#{auth.loggedIn}">
        <h:outputStylesheet library="css" name="style.css"  />
        <h:panelGroup layout="block" class="wrapper">
            <p:panel id="admin_panel" header="#{names.title}" style="margin-bottom:10px;">       
                <ui:include src="header.xhtml" /> 
                <p:panel id="new_person_panel" header="#{names.personCreatePanelName}" style="margin-bottom:10px;" styleClass="small">
                    <h:form id="new_person">
                       <h:panelGrid columns="3">
                           <p:outputLabel for="firstName" value="#{names.personAttributeFirstName}" />
                           <p:inputText id="firstName" value="#{person.firstName}" required="true" requiredMessage="#{names.personAttributeFirstNameMsg}"/>  
                           <p:message for="firstName" />
                           <p:outputLabel for="lastName" value="#{names.personAttributeLastName}" />
                           <p:inputText id="lastName" value="#{person.lastName}" required="true" requiredMessage="#{names.personAttributeLastNameMsg}"/>
                           <p:message for="lastName" />
                           <p:outputLabel for="identityCardNumber" value="#{names.personAttributeIdCardNumber}" />
                           <p:inputText id="identityCardNumber" value="#{person.identityCardNumber}" required="true" requiredMessage="#{names.personAttributeIdCardNumberMsg}"/>
                           <p:message for="identityCardNumber" />                          
                           <p:outputLabel  value="" />
                           <p:commandButton id="submit" icon="ui-icon-plus" value="#{names.buttonCreate}" ajax="false" actionListener="#{persons.add(person)}"/>
                       </h:panelGrid>
                   </h:form>                        
                </p:panel>
                    
                <p:panel id="all_persons_panel" header="#{names.allPersonsPanelName}" style="margin-bottom:10px;" styleClass="small">
                    <h:form id="edit_person">
                        <p:dataTable id="table_persons" var="p" value="#{persons.persons}"
                                     sortMode="multiple" paginator="true" rows="15" paginatorTemplate="{PageLinks}"
                                     emptyMessage="#{names.noEntries}">

                            <p:column sortBy="#{p.firstName}" headerText="#{names.personAttributeFirstName}">  
                                <h:outputText value="#{p.firstName}" />  
                            </p:column>
                              <p:column sortBy="#{p.lastName}" headerText="#{names.personAttributeLastName}">  
                                <h:outputText value="#{p.lastName}" />  
                            </p:column>                      
                            <p:column sortBy="#{p.identityCardNumber}" headerText="#{names.personAttributeIdCardNumber}">  
                                <h:outputText value="#{p.identityCardNumber}" />  
                            </p:column>   
                            <p:column style="width:100px;"> 
                                <p:commandButton id="viewButton" icon="ui-icon-pencil" value="#{names.buttonEdit}" action="#{persons.gotoEdit}">
                                    <f:param name="edit" value="#{p.id}"/>
                                </p:commandButton>                                                          
                            </p:column>
                        </p:dataTable>
                    </h:form>
                </p:panel>
            </p:panel>
        </h:panelGroup>
    </h:body>
    
</html>
